/*
 * Created on Oct 13, 2005 9:30:13 AM
 * 
 * $Id: LocalChannelImpl.java,v 1.1 2005/10/13 15:58:05 olu Exp $
 *
 */
package tripleo.framework.svr.storage;

import tripleo.framework.fs.FileOpFailure;

final class LocalChannelImpl implements Channel {
	
	private ss1_handler ass;

	public LocalChannelImpl(ss1_handler aAss) {
		ass=aAss;
	}

	public ss_request create(int aNature) {
		switch (aNature) {
		case 7: return new CreateRequestImpl(); 
		case 8: return new ReadFileRequestImpl();
		case 9: return new DeleteFileRequestImpl();
		default: throw new Error();
		}
	}

	public void default_success() {
		f = true;
	}

	public void fileop_failure(FileOpFailure aE) {
		channelResult = new ChannelResult();
		channelResult.failure = aE;
		f=false;
	}

	public void fileread_sucess(PartialStreamR aPartialstreamr) {
		channelResult = new ChannelResult();
		channelResult.stream = aPartialstreamr;
		f=true;
	}

	public ChannelResult result() {
		return channelResult;
	}
	
	public void string_success(String aString) {
		channelResult = new ChannelResult();
		channelResult.string = aString;
		f=true;
	}
	
	public boolean success() {
		return f;
	}

	ChannelResult channelResult;

	private boolean f;

	public void send(ss_request req) {
		if (req instanceof CreateRequest) {
			ass.create_file_req((CreateRequest)req, this);
		} else if (req instanceof ReadFileRequest) {
			ass.read_file_req((ReadFileRequest)req, this);
		} else if (req instanceof CreateRequest) {
			ass.delete_file_req((DeleteFileRequest)req, this);
		} else
			throw new Error();
	}

}
